home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Hardware / Misc. Tools / LFSR Verilog CAD Tool / Large Count < prev    next >
Encoding:
Text File  |  1993-06-03  |  2.5 KB  |  74 lines  |  [TEXT/OIUB]

  1. `timescale 1 ns / 100 ps
  2. /* Linear Feedback Shift Register 
  3.  * verilog module "LFSR"
  4.  * Generated by Macintosh application 'LFSR' 5/17/93 1:55 PM 
  5.  * company: Apple Computer 
  6.  * project: Display Controller 
  7.  * designer: Elmer Fudd
  8.  * prototypes:
  9.    LFSR(clk, preset, TC);
  10.    LFSR(.clk(CLOCK), .preset(PRESET), .TC(TC));
  11.  *
  12.  * The counter reaches terminal count after 2000000 positive edge clocks. 
  13.  * 'TC' is asserted high at the end of count.
  14.  * count is preset synchronously by an active high on 'preset'.
  15.  * The counter stops after terminal count and must be preset to count again. 
  16.  * The counter uses small auxiliary counter to detect for terminal count by counting all 'ones' being 
  17.  * shifted into the main counter. The preset of the small auxiliary counter is connected to the 
  18.  * input of the main shift register and terminal count is generated only when 23 '1' bits have shifted into the main counter.
  19.  * The auxiliary counter is 5 registers with two taps feedback to the input.
  20.  * The main counter consist of 23 registers with 2 taps feedback to the input. 
  21.  */
  22. module LFSR (clk, preset, TC);
  23. input clk;  
  24. input preset; 
  25. output TC; 
  26. reg [22:0] D;
  27. reg  [22:0] Q;
  28. wire isCounting;
  29. reg [4:0] AUX_D;
  30. reg [4:0] AUX_Q;
  31.  
  32. assign TC = &AUX_Q; 
  33. assign isCounting = preset | (isCounting & ~TC);
  34.  
  35. always @(Q or preset)
  36.     begin
  37.         casex ({preset}) // synopsys parallel_case full_case
  38.             'b1:            // retrigger presets from TC
  39.                 begin
  40.                     D = 'h1D4275; // preset to seed
  41.                 end
  42.             'b0:           // normal counting
  43.                 begin
  44.                     D[22:1] = Q[21:0];
  45.                     D[0] = (Q[22] ^ Q[4]) & isCounting;
  46.                 end
  47.         endcase
  48.     end // always
  49. // Auxiliary counter for detecting terminal count
  50. // counts 23 bits of consecutive '1's
  51. always @(D[0] or preset)
  52.     begin
  53.         casex ({D[0], preset}) // synopsys parallel_case full_case
  54.             'b0?,            // preset counter if zero detected
  55.             'b?1:            // retrigger presets from TC
  56.                 begin
  57.                     AUX_D = 'h14;
  58.                 end
  59.             'b10:           // normal counting
  60.                 begin
  61.                     AUX_D[4:1] = AUX_Q[3:0];
  62.                     AUX_D[0] = (AUX_Q[4] ^ AUX_Q[1]) & isCounting;
  63.                 end
  64.         endcase
  65.     end // always
  66.     
  67. // Shift register description
  68. always @(posedge clk)
  69.     begin
  70.         Q = D;     // make into D register
  71.         AUX_Q = AUX_D;     // make into D register
  72.     end
  73. endmodule // LFSR
  74.